home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
xinu.arc
/
XINU4.C
< prev
next >
Wrap
Text File
|
1986-01-03
|
11KB
|
402 lines
/* ssclock.c - stopclk, strtclk p. 134 */
# include <conf.h>
# include <kernel.h>
# include <proc.h>
# include <q.h>
# include <sleep.h>
/*-----------------------------------------------------------------------------
* stopclk -- put the clock in defer mode
*-----------------------------------------------------------------------------
*/
stopclk()
{
defclk++;
}
/*-----------------------------------------------------------------------------
* strtclk -- take the clock out of defer mode
*-----------------------------------------------------------------------------
*/
strtclk()
{
char ps;
int makeup;
int next;
disable(ps);
if ( defclk<=0 || --defclk>0 ) {
restore(ps);
return;
}
makeup = clkdiff;
preempt -= makeup;
clkdiff = 0;
if ( slnempty ) {
for (next=firstid(clockq) ;
next < NPROC && q[next].qkey < makeup ;
next=q[next].qnext) {
makeup -= q[next].qkey;
q[next].qkey = 0;
}
if (next < NPROC)
q[next].qkey -= makeup;
wakeup();
}
if (preempt <= 0)
resched();
restore(ps);
}
/* suspend.c - suspend p. 69 */
# include <conf.h>
# include <kernel.h>
# include <proc.h>
/*-----------------------------------------------------------------------------
* suspend -- suspend a process, placing it in hibernation
*-----------------------------------------------------------------------------
*/
SYSCALL suspend(pid)
int pid; /* id of process to suspend */
{
struct pentry *pptr; /* pointer to process table entry */
char ps; /* saved processor status */
int prio; /* priority returned */
disable(ps);
if (isbadpid(pid) || pid==NULLPROC ||
((pptr= &proctab[pid])->pstate !=PRCURR && pptr->pstate !=PRREADY)) {
restore(ps);
return(SYSERR);
}
if (pptr->pstate == PRREADY) {
dequeue(pid);
pptr->pstate = PRSUSP;
} else {
pptr->pstate = PRSUSP;
resched();
}
prio = pptr->pprio;
restore(ps);
return(prio);
}
/* ttycntl.c - ttycntl p. 182 */
# include <conf.h>
# include <kernel.h>
# include <tty.h>
# include <io.h>
# include <slu.h>
/*-----------------------------------------------------------------------------
* ttycntl -- control a tty device by setting modes
*-----------------------------------------------------------------------------
*/
ttycntl(devptr, func, addr)
struct devsw *devptr;
int func;
char *addr;
{
register struct tty *ttyp;
char ch;
char ps;
ttyp = &tty[devptr->dvminor];
switch ( func ) {
case TCSETBRK:
ttyp->ioaddr->ctstat |= SLUTBREAK;
break;
case TCRSTBRK:
ttyp->ioaddr->ctstat &= ~SLUTBREAK;
break;
case TCNEXTC:
disable(ps);
wait(ttyp->isem);
ch = ttyp->ibuff[ttyp->itail];
restore(ps);
signal(ttyp->isem);
return(ch);
case TCMODER:
ttyp->imode = IMRAW;
break;
case TCMODEC:
ttyp->imode = IMCOOKED;
break;
case TCMODEK:
ttyp->imode = IMCBREAK;
break;
case TCECHO:
ttyp->iecho = TRUE;
break;
case TCNOECHO:
ttyp->iecho = FALSE;
break;
case TCICHARS:
return(scount(ttyp->isem));
default:
return(SYSERR);
}
return(OK);
}
/* ttygetc.c - ttygetc p. 164 */
# include <conf.h>
# include <kernel.h>
# include <tty.h>
# include <io.h>
# include <slu.h>
/*-----------------------------------------------------------------------------
* ttygetc -- read one character from a tty device
*-----------------------------------------------------------------------------
*/
ttygetc(devptr)
struct devsw *devptr;
{
char ps;
int ch;
struct tty *iptr;
disable(ps);
iptr = &tty[devptr->dvminor];
wait(iptr->isem); /* wait for a character in buff */
ch = iptr->ibuff[iptr->itail++];
if (iptr->itail == IBUFLEN)
iptr->itail = 0;
restore(ps);
return(ch);
}
/* ttyiin.c - ttyiin, erase1, eputc, echoch p. 174 */
# include <conf.h>
# include <kernel.h>
# include <tty.h>
# include <io.h>
# include <slu.h>
/*-----------------------------------------------------------------------------
* ttyiin -- lower-half tty device driver for input interrupts
*-----------------------------------------------------------------------------
*/
INTPROC ttyiin(iptr)
register struct tty *iptr; /* pointer to tty block */
{
register struct csr *cptr;
register int ch;
Bool cerr;
int ct;
cptr = iptr->ioaddr;
if (iptr->imode == IMRAW) {
if (scount(iptr->isem) >= IBUFLEN) {
ch = cptr->crbuf;
return;
}
if ((ch=cptr->crbuf)&SLUERMASK) /* character error */
iptr->ibuff[iptr->ihead++] = (ch&SLUCHMASK) | IOCHERR;
else /* normal read complete */
iptr->ibuff[iptr->ihead++] = ch & SLUCHMASK;
if (iptr->ihead >= IBUFLEN) /* wrap buffer pointer */
iptr->ihead = 0;
signal(iptr->isem);
} else { /* cbreak or cooked mode */
cerr = ((ch=cptr->crbuf)&SLUERMASK) ? IOCHERR : 0;
ch &= SLUCHMASK;
if (ch == RETURN && iptr->icrlf)
ch = NEWLINE;
if (iptr->oflow) {
if (ch == iptr->ostart) {
iptr->oheld = FALSE;
cptr->ctstat = SLUENABLE;
return;
}
if (ch == iptr->ostop) {
iptr->oheld = TRUE;
return;
}
}
iptr->oheld = FALSE;
if (iptr->imode == IMCBREAK) { /* cbreak mode */
if (scount(iptr->isem) >= IBUFLEN) {
eputc(iptr->ifullc, iptr, cptr);
return;
}
iptr->ibuff[iptr->ihead++] = ch | cerr;
if (iptr->ihead >= IBUFLEN)
iptr->ihead = 0;
if (iptr->iecho)
echoch(ch, iptr, cptr);
if (scount(iptr->isem) < IBUFLEN)
signal(iptr->isem);
} else { /* cooked mode */
if (ch == iptr->ikillc && iptr->ikill) {
iptr->ihead -= iptr->icursor;
if (iptr->ihead < 0)
iptr->ihead += IBUFLEN;
iptr->icursor = 0;
eputc(RETURN, iptr, cptr);
eputc(NEWLINE, iptr, cptr);
return;
}
if (ch == iptr->ierasec && iptr->ierase) {
if (iptr->icursor > 0) {
iptr->icursor--;
erase1(iptr, cptr);
}
return;
}
if (ch == NEWLINE || ch == RETURN) {
if (iptr->iecho)
echoch(ch, iptr, cptr);
iptr->ibuff[iptr->ihead++] = ch | cerr;
if (iptr->ihead >= IBUFLEN)
iptr->ihead = 0;
ct = iptr->icursor+1; /* +1 for \n or \r */
iptr->icursor = 0;
signaln(iptr->isem, ct);
return;
}
ct = scount(iptr->isem);
ct = ct < 0 ? 0 : ct;
if ((ct + iptr->icursor) >= IBUFLEN-1) {
eputc(iptr->ifullc,iptr,cptr);
return;
}
if (iptr->iecho)
echoch(ch,iptr,cptr);
iptr->icursor++;
iptr->ibuff[iptr->ihead++] = ch | cerr;
if (iptr->ihead >= IBUFLEN)
iptr->ihead = 0;
}
}
}
/*-----------------------------------------------------------------------------
* erase1 -- erase one character honoring erasing backspace
*-----------------------------------------------------------------------------
*/
LOCAL erase1(iptr,cptr)
struct tty *iptr;
struct csr *cptr;
{
char ch;
if (--(iptr->ihead) < 0)
iptr->ihead += IBUFLEN;
ch = iptr->ibuff[iptr->ihead];
if (iptr->iecho) {
if (ch < BLANK || ch == 0177) {
if (iptr->evis) {
eputc(BACKSP,iptr,cptr);
if (iptr->ieback) {
eputc(BLANK,iptr,cptr);
eputc(BACKSP,iptr,cptr);
}
}
eputc(BACKSP,iptr,cptr);
if (iptr->ieback) {
eputc(BLANK,iptr,cptr);
eputc(BACKSP,iptr,cptr);
}
} else {
eputc(BACKSP,iptr,cptr);
if (iptr->ieback) {
eputc(BLANK,iptr,cptr);
eputc(BACKSP,iptr,cptr);
}
}
} else
cptr->ctstat = SLUENABLE;
}
/*-----------------------------------------------------------------------------
* echoch -- echo a character with visual and ocrlf options
*-----------------------------------------------------------------------------
*/
LOCAL echoch(ch, iptr, cptr)
char ch; /* character to echo */
struct tty *iptr; /* pntr to I/O block for this devptr */
struct cst *cptr; /* csr address for this devptr */
{
if ((ch == NEWLINE || ch == RETURN) && iptr->ecrlf) {
eputc(RETURN,iptr,cptr);
eputc(NEWLINE,iptr,cptr);
} else if ((ch < BLANK || ch == 0177) && iptr->evis) {
eputc(UPARROW,iptr,cptr);
eputc(ch+0100,iptr,cptr); /* make it printable */
} else {
eputc(ch,iptr,cptr);
}
cptr->ctstat = SLUENABLE;
}
/*-----------------------------------------------------------------------------
* eputc -- put one character in the echo queue
*-----------------------------------------------------------------------------
*/
LOCAL eputc(ch,iptr,cptr)
char ch;
struct tty *iptr;
struct csr *cptr;
{
iptr->ebuff[iptr->ehead++] = ch;
if (iptr->ehead >= EBUFLEN)
iptr->ehead = 0;
cptr->ctstat = SLUENABLE;
}
/* ttyinit.c - ttyinit p. 174 */
# include <conf.h>
# include <kernel.h>
# include <tty.h>
# include <io.h>
# include <slu.h>
/*-----------------------------------------------------------------------------
* ttyinit -- initialize buffers and modes for a tty line
*-----------------------------------------------------------------------------
*/
ttyinit(devptr)
struct devsw *devptr;
{
register struct tty *iptr;
register struct csr *cptr;
int i, junk, isconsole;
/* set up interrupt vector and interrupt dispatch table */
iptr = &tty[devptr->dvminor];
iosetvec(devptr->dvnum, iptr, iptr);
devptr->dvioblk = iptr; /* fill tty control block */
isconsole = (devptr->dvnum == CONSOLE); /* make console cooked */
iptr->ioaddr = devptr->dvcsr; /* copy in csr address */
iptr->ihead = iptr->itail = 0; /* empty input queue */
iptr->isem = screate(0); /* chars read so far = 0 */
iptr->osem = screate(OBUFLEN); /* buffer available = all */
iptr->odsend = 0; /* sends delayed so far */
iptr->ohead = iptr->otail = 0; /* output queue empty */
iptr->ehead = iptr->etail = 0; /* echo queue empty */
iptr->imode = (isconsole ? IMCOOKED : IMRAW);
iptr->iecho = iptr->evis = isconsole; /* echo console input */
iptr->ierase = iptr->ieback = isconsole;/* console honors erase */
iptr->ierasec = BACKSP; /* using ^h */
iptr->ecrlf = iptr->icrlf = isconsole; /* map RETURN on input */
iptr->ocrlf = iptr->oflow = isconsole;
iptr->ikill = isconsole; /* set line kill == @ */
iptr->ikillc = ATSIGN;
iptr->oheld = FALSE;
iptr->ostart = STRTCH;
iptr->ostop = STOPCH;
iptr->icursor = 0;
iptr->ifullc = TFULLC;
cptr = (struct csr *)devptr->dvcsr;
junk = cptr->crbuf; /* clear receiver and.. */
cptr->crstat = SLUENABLE; /* enable input interrupts */
cptr->ctstat = SLUDISABLE; /* disable output interrupts */
}